﻿using System;

namespace Basmus.Values
{
    public class SchemeKey : IEquatable<SchemeKey>
    {
        public bool IsDefault { get; private set; }
        
        public string Key { get; private set; }

        public static SchemeKey Default = new SchemeKey
                                              {
                                                  IsDefault = true
                                              };

        public static SchemeKey Create(string key)
        {
            return new SchemeKey
                       {
                           IsDefault = false,
                           Key = key
                       };
        }

        private SchemeKey()
        {
            
        }

        public bool Equals(SchemeKey other)
        {
            return IsDefault == other.IsDefault && (IsDefault || Key == other.Key);
        }

        public override int GetHashCode()
        {
            if (IsDefault || Key == null)
            {
                return IsDefault.GetHashCode();
            }
            return IsDefault.GetHashCode() ^ Key.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            return Equals((SchemeKey) obj);
        }

        public static bool operator ==(SchemeKey a, SchemeKey b)
        {
            return a.Equals(b);
        }

        public static bool operator !=(SchemeKey a, SchemeKey b)
        {
            return !(a == b);
        }
    }
}
